var express = require('express');
var router = express.Router();
const User = require('../models/user.model')
/* GET users listing. */
router.get('/', function(req, res, next) {
  res.json('respond with a resource');
});

/**
 * 保存用户
 */
router.post('/save', async (req, res) => {
  const data = req.body
  const user = await User.create(data)
  res.json(user)
})

router.get('/list', async (req, res) => {
  // const users = await User.find({}, 'name password')
  const users = await User.find({}, ['name', 'password'])
  // const users = await User.find().select({password: 0})
  res.json(users)
})

module.exports = router;
